package com.zhkj.txg.module.group.model

import com.zhkj.lib.http.BaseManager
import com.zhkj.lib.http.BaseResponse
import com.zhkj.lib.http.ResponseSubscribeListener
import com.zhkj.lib.http.SubscribeListener
import com.zhkj.txg.module.group.entity.GroupListResponse
import com.zhkj.txg.module.product.entity.ProductResponse
import io.reactivex.disposables.Disposable

class GroupManager : BaseManager<GroupApi>(GroupApi::class.java) {
    /**
     * 获取拼团列表
     */
    fun getPromotion(
        token: String,
        page: Int,
        rows: Int,
        listener: SubscribeListener<GroupListResponse>
    ): Disposable {
        val cart = apiService.getPromotion(token, page, rows)
        return subscribe(cart, ResponseSubscribeListener(listener))
    }

    /**
     * 获取拼团列表
     */
    fun getGroup(
        token: String,
        page: Int,
        rows: Int,
        listener: SubscribeListener<GroupListResponse>
    ): Disposable {
        val cart = apiService.getGroup(token, page, rows)
        return subscribe(cart, ResponseSubscribeListener(listener))
    }

    /**
     * 获取拼团产品详情
     */
    fun getProduct(
        token: String,
        id: String,
        shareId: Int,
        listener: SubscribeListener<ProductResponse>
    ): Disposable {
        val cart = apiService.getProduct(token, id, shareId)
        return subscribe(cart, ResponseSubscribeListener(listener))
    }

    /**
     * 收藏商品
     */
    fun collectProduct(
        token: String, goodsId: Long,
        listener: SubscribeListener<BaseResponse>
    ): Disposable {
        val collectProduct = apiService.collectProduct(token, goodsId)
        return subscribe(collectProduct, ResponseSubscribeListener(listener))
    }
}